nclsfr = length(classifier_feature_val);

while 1
    cid = input(['Which classifier to analyse (1-' num2str(nclsfr) ')?']);
    if isempty(cid) || cid ==0
        break;
    end
    for i=cid
        clsfr = classifier_feature_val{i}.features;
        ncls = length(clsfr);
        nf = length(clsfr{1}.mu);
        perr_arr = zeros(nf, 1);
        th_arr = zeros(nf, ncls-1);
        for f = 1:nf
            mu = zeros(ncls, 1);
            sigma = zeros(ncls, 1);
            for cls = 1:ncls
                mu(cls) = clsfr{cls}.mu(f);
                sigma(cls) = clsfr{cls}.sigma(f);
            end
            [perr, th] = norm_metric(mu, sigma);
            perr_arr(f) = perr;
            th_arr(f,:) = th;
        end
        [perr_arr rank] = sort(perr_arr);
        th_arr = th_arr(rank, :);
        
        % output results
        disp(['Classifier ' i]);
        disp('    Top ranked features');
        for j=1:nf
            fname = feature_set_name{rank(j)};
            disp(['        ' num2str(j) ': ' fname ' Estimated error rate: ' num2str(perr_arr(j))]);
        end
        while 1
            fid = input('Which feature to plot?');
            if isempty(fid) || ~fid
                break;
            end
            figure;
            draw_feature(classifier_feature_val, classifiers, i, rank(fid), th_arr(fid, :));
            title(strrep(strrep(feature_set_name{rank(fid)},'_','\_'),'/','_'));
        end
        fid = input('Select features for this classifier: ');
        if ~isempty(fid)
            classifiers(i).features = {};
            classifiers(i).feature_val = cell(0,1);
            for f=fid
                classifiers(i).features{end+1} = feature_set_name{rank(f)};
            end
            for j=1:length(classifiers(i).classes)
                classifiers(i).feature_val{j}.mu = classifier_feature_val{i}.features{j}.mu(rank(fid));
                classifiers(i).feature_val{j}.sigma = classifier_feature_val{i}.features{j}.sigma(rank(fid));
            end
        end
    end
end
